/**
 * Created by IAN on 2016/10/14.
 */
$(function () {

    var sel = $.Params.create();
    sel.addParams("page", 0);
    sel.addParams("rows", rows);
    getData();

    //查询
    $("#searchBtn").on("click", function () {
        var title = $("#title").val();
        var type = $("#type").val();
        if(type != "0"){
            sel.addParams("type", type);
        }else{
            sel.addParams("type", undefined);
        }
        if (title != "") {
            sel.addParams("pTitle", title);
        } else {
            sel.addParams("pTitle", undefined);
        }
        getData();
    })

    //判断checkbox状态
    $("#selAll").on("click", function () {
        if (!$(this).attr("checked")) {
            $("input[type=checkbox]").attr("checked", "checked")
        } else {
            $("input[type=checkbox]").removeAttr("checked");
        }
    })

    //添加事件
    $('#addDataBtn').on("click", function () {
        window.location.href = "speakHostAdd.html";
    });

    //删除事件
    $('#delBtn').on("click", function () {
        var params = getCheckData();
        if (params != "") {
            if (confirm("确定要删除吗！")) {
                var del = $.Params.create();
                //del.addParams("params", params)
                del.ajax("delete", getMeetIP() + "speakHost?params=" + params, function (data) {
                        alert("删除成功！");
                        getData();
                    
                })
            }
        } else {
            alert("请至少选中一项");
        }
    });

    //获取数据
    function getData() {
        getPageData("get", sel, getMeetIP() + "speakHost", function (data) {
            
                var html = "";
                if (data.count > 0) {
                    $.each(data.rows, function (i, val) {
					var type = "";
					if(val.type == 1){
					type = "讲者";
					}else if(val.type == 2){
					type = "主持";
					}
					if(val.hospitalName == null || val.hospitalName =="null"){
						val.hospitalName = "";
					}
					if(val.tel == null || val.tel =="null"){
						val.tel = "";
					}
                        html += "<tr role='row'' class='even'>" +
                            "<td><input eid='" + val.id + "' onclick='getCheck(this)' type='checkbox' class='classOption'></td>" +
                            "<td><img  style = 'width:56px;heigh:56px;' src = '" + getMeetUrlIP() + "data/headImg/" + val.headImg + "'></img></td>" +
                            "<td>" + val.name + "</td>" +
                            "<td>" + val.tel + "</td>" +
                            "<td>" + val.hospitalName + "</td>" +
							//"<td>" + type + "</td>" +
                            "<td><button type='button' class='btn btn-primary'  onclick='updateInfo(\"" + val.id + "\")'>修改</button></td>" +
                            "</tr>";
                    });

                } else {
                    html = "<tr><td>暂无数据</td></tr>"
                }
                $("#listContainer").html(html);
        })
    }
    updateInfo = function (eid) {
        window.location.href = "speakHostUpdate.html?eid=" + eid;
    }
});

